//========================================================================
// FILENAME : looptimer.c
// CREATED : 08-05-2009
// AUTHOR : Jesper Aagaard Vuholm
// DESCR. : This file contains the setup of timer 0 that is used to count
//          the time of each run in our main loop. The measured time is
//          then used in the gyro math to extract the angle.
//------------------------------------------------------------------------
//
// REV. DATE/AUTHOR CHANGE DESCRIPTION
// 1.00 08-05-2009/Jesper prototype functions created.
// 1.01 09-05-2009/Jesper controlling functions finished and implemented.
//========================================================================
#include "LoopTimerDriver.h"

#define sbi(port,pin)    port |= 1<<pin    //set bit
#define cbi(port,pin)    port &= ~(1<<pin) //clear bit

//=============================================================
// METHOD : void looptimer_init(void)
// DESCR. : Sets the correct registers to enable timer 0.
//          with a prescale of 8 bit.
//=============================================================
void looptimer_init(void)
{
	///////////////////////
	//   TIMER 0 SETUP   //
	///////////////////////

	// prescaling with 8bit = (1sek/(10Mhz/8))*125 = 100 uS. pr. rollover.
	TCCR0B |= (1<<CS01);

	// start timer 0 counting from 0.
	TCNT0 = 0;

	// unmasking timer 0 interrupt.
	TIMSK0 = 0x01;
}
